#include <cmath>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <algorithm>
#include  <\Trnsys17\Compilers\Cpp-Mvs2003\Include\TRNSYS.h> //TRNSYS acess functions (allow to acess TIME etc.) 
//************************************************************************
//************************************************************************
// Object: Preheater
// IISiBat Model: Type134
// 
// Author: 
// Editor: 
// Date:	 February 15, 2017 last modified: February 15, 2017
// 
// 
// *** 
// *** Model Parameters 
// *** 
//			D_s	m [-Inf;+Inf]
//			d_o	m [-Inf;+Inf]
//			Nss	- [-Inf;+Inf]
//			di	m [-Inf;+Inf]
//			pt	m [-Inf;+Inf]
//			l_c	m [-Inf;+Inf]
//			Xl	m [-Inf;+Inf]
//			Xt	m [-Inf;+Inf]
//			wp	m [-Inf;+Inf]
//			Np	m [-Inf;+Inf]
//			Dotl	m [-Inf;+Inf]
//			delta_tb	m [-Inf;+Inf]
//			delta_sb	m [-Inf;+Inf]
//			disp_tubo	- [-Inf;+Inf]

// *** 
// *** Model Inputs 
// *** 
//			tiptubo	- [-Inf;+Inf]
//			T5	C [-Inf;+Inf]
//			Vdot5	m^3/s [-Inf;+Inf]
//			T2	C [-Inf;+Inf]
//			Nt_p	- [-Inf;+Inf]
//			Ro_f	any [-Inf;+Inf]
//			Ri_f	- [-Inf;+Inf]
//			Kw	W/m.K [-Inf;+Inf]
//			Vdot2	m^3/s [-Inf;+Inf]
//			T3	C [-Inf;+Inf]
//			Tamb	C [-Inf;+Inf]
//			Nb	- [-Inf;+Inf]
//			T2_trans	C [-Inf;+Inf]
//			T5_trans	C [-Inf;+Inf]

// *** 
// *** Model Outputs 
// *** 
//			Ao_cr	m^2 [-Inf;+Inf]
//			Ao_bp	m^2 [-Inf;+Inf]
//			Ao_sb	m^2 [-Inf;+Inf]
//			Ao_w	- [-Inf;+Inf]
//			Ao_tb	- [-Inf;+Inf]
//			h_pr_o_real	W/m^2.K [-Inf;+Inf]
//			Ao_t	m^2 [-Inf;+Inf]
//			h_pr_i	W/m^2.K [-Inf;+Inf]
//			Uo	W/K [-Inf;+Inf]
//			T6	C [-Inf;+Inf]
//			Q23	W [-Inf;+Inf]
//			deltaP_pr_o	Pa [-Inf;+Inf]
//			Lasum	m [-Inf;+Inf]
//			Qperdidas	W [-Inf;+Inf]
//			Vdot3	m^3/s [-Inf;+Inf]
//			eff	- [-Inf;+Inf]
//			NTU	- [-Inf;+Inf]
//			T3	C [-Inf;+Inf]
//			T3_tran	C [-Inf;+Inf]
//			Q_pre_tran	W [-Inf;+Inf]
//			T6_trans	C [-Inf;+Inf]
//			deltaP_pr_i	Pa [-Inf;+Inf]

// *** 
// *** Model Derivatives 
// *** 

// (Comments and routine interface generated by TRNSYS Studio)
//************************************************************************

//
extern "C" __declspec(dllexport)
int TYPE134(
	double &time,  // the simulation time
	double xin[],  // the array containing the component InpUTS
	double xout[], // the array which the component fills with its appropriate OUTPUTS
	double &t,     // the array containing the dependent variables for which the derivatives are evaluated 
	double &dtdt,  // the array containing the derivatives of T which are evaluated 
	double par[],  // the array containing the PARAMETERS of the component
	int info[],    // the information array described in Section 3.3.3 of the manual
	int icntrl     // the control array described in Section 3.3.4 of the manual
)
{
	//*************************************************************************
	//*** TYPE implementation
	//*** This function will be called by TRNSYS 
	//*** - once at the beginning of the simulation for initialization
	//*** - once at the beginning of every timestep for initialization
	//*** - once for each iteration of the TRNSYS solver
	//*** - once at the end of each timestep for cleanup
	//*** - once at the end of the simulation for cleanup
	//*************************************************************************
	// 
	//***
	//*** WARNING: explanations in the TRNSYS manual use FORTRAN conventions for 
	//***          array indices. Subtract 1 to obtain 0-based C or C++ conventions. 
	//*** Example: 
	//***          TRNSYS manual: info(6) = number of OUTPUTS 
	//***          -> write no = info[5] to obtain number of outputs in C or C++
	//***
	//*** We also spell variables in lower case according to C tradition, while they
	//*** are spelled in uppercase in the TRNSYS manual (according to FORTRAN tradition)
	//*** 


	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------

	// *** STANDARD TRNSYS DECLARATIONS
	int npar = 14;   // number of parameters we expect
	int nin = 14;   // number of inputs
	int nout = 22; // number of outputs
	int nder = 0;   // number of derivatives
	int iunit; // UNIT number ('serial number' of the component, from the input file (the 'deck')
	int itype; // TYPE number (component number) 
			   // read context information from TRNSYS
			   // (uncomment lines as required)
	info[5] = nout;  // number of outputs 

	iunit = info[0]; // UNIT number
	itype = info[1]; // TYPE number

					 //info[2]	; // number of INPUTS specified by the user of the component 
					 //info[3]	; // number of PARAMETERS specified by the user of the component
					 //info[4]	; // number of DERIVATIVES specified by the user of the component
					 //info[5]	; // number of OUTPUTS specified by the user of the component

					 //info[6]	; // number of iterative calls to the UNIT in the current timestep
					 // -2 = initialization
					 // -1	= initial call in simulation for this UNIT
					 //  0 = first call in timestep for this UNIT.
					 //  1	= second call in timestep for this UNIT, etc.

					 //info(7)	; // total number of calls to the UNIT in the simulation
					 // *** inform TRNSYS about properties of this type
	info[8] = 0; // indicates whether TYPE depends on the passage of time: 0=no
	info[9] = 0; //	use to allocate storage (see Section 3.5 of the TRNSYS manual): 0 = none
				 // info[10]; // indicates number of discrete control variables (see Section 3.3.4 of the TRNSYS manual)
				 //-----------------------------------------------------------------------------------------------------------------------

				 //-----------------------------------------------------------------------------------------------------------------------
				 //    ADD DECLARATIONS AND DEFINITIONS FOR THE USER-VARIABLES HERE

				 //-----------------------------------------------------------------------------------------------------------------------

	//    PARAMETERS
	double D_s;
	double d_o;
	double Nss;
	double di;
	double pt;
	double l_c;
	double Xl;
	double Xt;
	double wp;
	double Np;
	double Dotl;
	double delta_tb;
	double delta_sb;
	double disp_tubo;

	//    INPUTS
	double tiptubo;
	double T5;
	double Vdot5;
	double T2;
	double Nt_p;
	double Ro_f;
	double Ri_f;
	double Kw;
	double Vdot2;
	double T3;
	double Tamb;
	double Nb;
	double T2_trans;
	double T5_trans;

	//-----------------------------------------------------------------------------------------------------------------------
	//       READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER
	D_s = par[0];
	d_o = par[1];
	Nss = par[2];
	di = par[3];
	pt = par[4];
	l_c = par[5];
	Xl = par[6];
	Xt = par[7];
	wp = par[8];
	Np = par[9];
	Dotl = par[10];
	delta_tb = par[11];
	delta_sb = par[12];
	disp_tubo = par[13];

	//-----------------------------------------------------------------------------------------------------------------------
	//    RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER

	tiptubo = xin[0];
	T5 = xin[1];
	Vdot5 = xin[2];
	T2 = xin[3];
	Nt_p = xin[4];
	Ro_f = xin[5];
	Ri_f = xin[6];
	Kw = xin[7];
	Vdot2 = xin[8];
	T3 = xin[9];
	Tamb = xin[10];
	Nb = xin[11];
	T2_trans = xin[12];
	T5_trans = xin[13];
	iunit = info[0];
	itype = info[1];

	//-----------------------------------------------------------------------------------------------------------------------
	//    SET THE VERSION INFORMATION FOR TRNSYS
	if (info[6] == -2)
	{
		info[11] = 16;
		// add additional initialisation code here, if any
		return 1;
	}
	//-----------------------------------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------------------------------
	//    DO ALL THE VERY LAST CALL OF THE SIMULATION MANIPULATIONS HERE
	if (info[7] == -1)
		return 1;
	//-----------------------------------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------------------------------
	//    PERFORM ANY 'AFTER-ITERATION' MANIPULATIONS THAT ARE REQUIRED HERE
	//    e.g. save variables to storage array for the next timestep
	if (info[12]>0)
	{
		//	   nitems=0;
		//	   stored[0]=... (if NITEMS > 0)
		//        setStorageVars(STORED,NITEMS,INFO)
		return 1;
	}
	//-----------------------------------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------------------------------
	//    DO ALL THE VERY FIRST CALL OF THE SIMULATION MANIPULATIONS HERE
	if (info[6] == -1) // first call of this component in the simulation
	{
		//       SET SOME INFO ARRAY VARIABLES TO TELL THE TRNSYS ENGINE HOW THIS TYPE IS TO WORK
		info[5] = nout;
		info[8] = 1;
		info[9] = 0;	// STORAGE FOR VERSION 16 HAS BEEN CHANGED				

						//       SET THE REQUIRED NUMBER OF INPUTS, PARAMETERS AND DERIVATIVES THAT THE USER SHOULD SUPPLY IN THE INPUT FILE
						//       IN SOME CASES, THE NUMBER OF VARIABLES MAY DEPEND ON THE VALUE OF PARAMETERS TO THIS MODEL....
		nin = 14;
		npar = 14;
		nder = 0;

		//       CALL THE TYPE CHECK SUBROUTINE TO COMPARE WHAT THIS COMPONENT REQUIRES TO WHAT IS SUPPLIED IN 
		//       THE TRNSYS INPUT FILE
		int dummy = 1;
		TYPECK(&dummy, info, &nin, &npar, &nder);

		//       SET THE NUMBER OF STORAGE SPOTS NEEDED FOR THIS COMPONENT
		//         nitems=0;
		//	     setStorageSize(nitems,info)

		//       RETURN TO THE CALLING PROGRAM
		return 1;
	}


	//-----------------------------------------------------------------------------------------------------------------------
	//    DO ALL OF THE INITIAL TIMESTEP MANIPULATIONS HERE - THERE ARE NO ITERATIONS AT THE INTIAL TIME
	if (time < (getSimulationStartTime() +
		getSimulationTimeStep() / 2.0))
	{
		//       SET THE UNIT NUMBER FOR FUTURE CALLS
		iunit = info[0];
		itype = info[1];

		//       CHECK THE PARAMETERS FOR PROBLEMS AND RETURN FROM THE SUBROUTINE IF AN ERROR IS FOUND
		//         if(...) TYPECK(-4,INFO,0,"BAD PARAMETER #",0)

		//       PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL VALUES OF THE OUTPUTS HERE
		//		 Ao_cr
		xout[0] = 0;
		//		 Ao_bp
		xout[1] = 0;
		//		 Ao_sb
		xout[2] = 0;
		//		 Ao_w
		xout[3] = 0;
		//		 Ao_tb
		xout[4] = 0;
		//		 h_pr_o_real
		xout[5] = 0;
		//		 Ao_t
		xout[6] = 0;
		//		 h_pr_i
		xout[7] = 0;
		//		 Uo
		xout[8] = 0;
		//		 T6
		xout[9] = 0;
		//		 Q23
		xout[10] = 0;
		//		 deltaP_pr_o
		xout[11] = 0;
		//		 Lasum
		xout[12] = 0;
		//		 Qperdidas
		xout[13] = 0;
		//		 Vdot3
		xout[14] = 0;
		//		 eff
		xout[15] = 0;
		//		 NTU
		xout[16] = 0;
		//		 T3
		xout[17] = 0;
		//		 T3_tran
		xout[18] = 0;
		//		 Q_pre_tran
		xout[19] = 0;
		//		 T6_trans
		xout[20] = 0;
		//		 deltaP_pr_i
		xout[21] = 0;

		//       PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL STORAGE VARIABLES HERE
		//         nitems=0;
		//	   stored[0]=...

		//       PUT THE STORED ARRAY IN THE GLOBAL STORED ARRAY
		//         setStorageVars(stored,nitems,info)

		//       RETURN TO THE CALLING PROGRAM
		return 1;

	}
	//-----------------------------------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------------------------------
	//    *** ITS AN ITERATIVE CALL TO THIS COMPONENT ***
	//-----------------------------------------------------------------------------------------------------------------------


	//-----------------------------------------------------------------------------------------------------------------------
	//    RETRIEVE THE VALUES IN THE STORAGE ARRAY FOR THIS ITERATION
	//      nitems=
	//	    getStorageVars(stored,nitems,info)
	//      stored[0]=
	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------
	//    CHECK THE INPUTS FOR PROBLEMS
	//      if(...) TYPECK(-3,INFO,'BAD INPUT #',0,0)
	//	if(IERROR.GT.0) RETURN 1
	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------
	//    *** PERFORM ALL THE CALCULATION HERE FOR THIS MODEL. ***
	//-----------------------------------------------------------------------------------------------------------------------

	//		ADD YOUR COMPONENT EQUATIONS HERE; BASICALLY THE EQUATIONS THAT WILL
	//		CALCULATE THE OUTPUTS BASED ON THE PARAMETERS AND THE INPUTS.	REFER TO
	//		CHAPTER 3 OF THE TRNSYS VOLUME 1 MANUAL FOR DETAILED INFORMATION ON
	//		WRITING TRNSYS COMPONENTS.


	//DEFINICION DE VARIABLES
	//DEFINICION DE VARIABLES
	//DEFINICION DE VARIABLES
    #define M_PI 3.14159265358979323846 /* pi */
	double Ct, theta_b, theta_ctl, Fw, Nt_w, Afr_t, Dctl, N_t, Afr_w, Ao_w, Lc_eff, Nr_cw, Fc, Nr_cc, d1, Ao_tb, Ao_sb, Lasum, Lb_c_, Lb_i, Lb_o, Ao_cr, Ao_bp, F_bp;
	double T3asum, Tm_pr_in, Tpri1, Tpri2, Tpri3, Tpri4, Tpri5, rho_pr_in, Pr_pr_in, miu_pr_in, K_pr_in, Cp_pr_in, mdot2, num_1, num_2, num_3, num_4, num_5, Ao_t;
	double Re_pr_i, pot_Re_pr_i, pot_Pr_pr_in, Nu_pr_i, h_pr_i, num_6, num_7, num_8, num_9, num_10, num_11, num_12, num_13;
	double T6, Tpro1, Tpro2, Tpro3, Tpro4, Tpro5, Tm_pr_o, rho_pr_o, Pr_pr_o, miu_pr_o, K_pr_o, Cp_pr_o;
	double Re_pr_o1, Re_pr_o2, Re_pr_o3, Re_pr_o4, Re_pr_o5, raz_Pr_pr_o, pot_Pr_pr_o, raz_Xl_Xt, pot_Xl_Xt, pot_Pr_pr_o2, pot_Pr_pr_o3, Nu_pr_o, h_pr_o;
	double Jc, r_s, rlm, Jl, Nss_plus, rb, Li_plus, Lo_plus, n, Nr_c, C_1, num_14, pro_Nssplus, pot_Nssplus, Jb, num_15, pot_Li_plus, pot_Lo_plus, Js;
	double raz_Nr_c, num_16, pot_Jr, Jr, h_pr_o_real;
	double mdot5, G_pr_o, Ts, Ts1, Ts2, Ts3, Ts4, Ts5, Re_pr_o, Pr_pr_s;
	double Uo, Uo_inv, Delta_T1, Delta_T2, LMTD, Asup_asum, Q_23, Q_56, Q_t;
	double L_calc, Asup_calc, error;
	double R1, R2, R3, R4, R5, R6, R7, R8, hamb, Q_util, Tsup1, Tsup2;
	double D, pro_Areas, pot_Areas, p_p, pot_rlm, pro_Nss_plus2, pot_Nss_plus2, sita_b, sita_l, Gw, delta_Pcr, delta_Pw, n_prima, sita_s;
	double delta_pio, deltaP_pr_o;
	double eff, c_asterisco, C_pr_i, C_pr_o, C_min, C_max, q_max, F_pot, eff_1, potsumC_as, E, T6asum, Tsup2asum;
	double potNTU_l, NTU, A_prec;
	int contador = 0;
	int iteracion = 0;


//MODULO DE DISEO DEL INTERCAMBIADOR//////////
	//CALCULO DE LAS RELACIONES GEOMETRICAS DEL PRECALENTADOR
	Dctl = Dotl - d_o;
	if ((disp_tubo == 45) || (disp_tubo == 90))
	{
		Ct = 1;
	}
	if ((disp_tubo == 30) || (disp_tubo == 60))
	{
		Ct = 0.86;
	}
	theta_ctl = 2 * acos((D_s - 2 * l_c) / Dctl);
	N_t = (M_PI / 4 * (Dctl*Dctl)) / (Ct*(pt*pt));
	theta_b = 2 * acos(1 - 2 * l_c / D_s);

	Fw = theta_ctl / (2 * M_PI) - (sin(theta_ctl) / (2 * M_PI));
	Nt_w = Fw*N_t;
	Afr_t = M_PI / 4 * (d_o*d_o)*Fw*N_t;
	Afr_w = (D_s*D_s) / 4 * (theta_b / 2 - (1 - 2 * l_c / D_s)*(sin(theta_b / 2)));
	Ao_w = Afr_w - Afr_t;
	Lc_eff = l_c - 1 / 2 * (D_s - Dctl);
	Nr_cw = 0.8*Lc_eff / Xl;
	Fc = 1 - 2 * Fw;
	Nr_cc = (D_s - 2 * l_c) / Xl;
	d1 = d_o + delta_tb;
	Ao_tb = (M_PI*d_o*(d1 - d_o)*N_t*(1 - Fw)) / 2;
	Ao_sb = (M_PI*D_s*delta_sb*(1 - theta_b / (2 * M_PI))) / 2;

	Tsup2asum = 59;
	T6asum = T5 - 0.5;

	Lasum = 1;

	while (contador <= 100000) {
		error = 0;
		Lb_c_ = Lasum / (2.2 + (Nb - 1));
		Lb_i = 1.1*Lb_c_;
		Lb_o = 1.1*Lb_c_;
		Ao_cr = (D_s - Dotl + ((2 * Dctl / Xt)*(pt - d_o)))*Lb_c_;
		//Nb = ((Lasum - Lb_i - Lb_o) / Lb_c_) + 1;
		Ao_bp = (D_s - Dotl + (0.5*Np*wp))*Lb_c_;
		F_bp = Ao_bp / Ao_cr;
		Nt_p = N_t / Np;
		Ao_t = M_PI/4*(di*di*Nt_p);

		//CALCULO DEL COEFICIENTE DE TRANSFERENCIA DE CALOR POR LOS TUBOS (CONVECCIN FORZADA INTERNA)
		//Clculo de las propiedades trmodinamicas del fluido (agua residual)
		T3asum = T3;
		n = 0.6;
		num_1 = 5;
		num_2 = 4;
		num_3 = 3;
		num_4 = 2;
		num_5 = 1;
		num_6 = 0.4;
		num_7 = 0.5;
		num_8 = 0.63;
		num_9 = 0.8;
		num_10 = 0.25;
		num_11 = 0.6;
		num_12 = 0.2;
		num_13 = 0.36;
		num_14 = 1 / 3;
		num_15 = (1 - n);
		Tm_pr_in = (T3asum + T2) / 2;
		Tpri1 = pow(Tm_pr_in, num_1);
		Tpri2 = pow(Tm_pr_in, num_2);
		Tpri3 = pow(Tm_pr_in, num_3);
		Tpri4 = pow(Tm_pr_in, num_4);
		Tpri5 = pow(Tm_pr_in, num_5);

		rho_pr_in = 1.00000751E+03 + 4.12453182E-02*Tpri5 - 7.26158539E-03*Tpri4 + 3.89860058E-05*Tpri3 - 1.21356829E-07*Tpri2;
		Pr_pr_in = 1.32916100E+01 - 4.30437257E-01*Tpri5 + 7.47644446E-03*Tpri4 - 6.61443405E-05*Tpri3 + 2.29809176E-07*Tpri2;
		miu_pr_in = 1.74208697E-03 - 5.10568150E-05*Tpri5 + 8.47487316E-07*Tpri4 - 7.35177149E-09*Tpri3 + 2.52888709E-11*Tpri2;
		K_pr_in = 5.47259845E-01 + 2.08355828E-03*Tpri5 - 5.71874184E-06*Tpri4 - 7.36319189E-08*Tpri3 + 4.03698327E-10*Tpri2;
		Cp_pr_in = 4.19918341E+00 - 1.25654652E-03*Tpri5 + 3.16877370E-05*Tpri4 - 3.68914621E-07*Tpri3 + 1.97518528E-09*Tpri2;
		mdot2 = Vdot2*rho_pr_in;

		//Clculo del nmero de Reynolds y del nmero de Nusselt

		Re_pr_i = mdot2*di / (Ao_t*miu_pr_in);
		pot_Re_pr_i = pow(Re_pr_i, num_9);
		pot_Pr_pr_in = pow(Pr_pr_in, num_6);
		Nu_pr_i = 0.023*pot_Re_pr_i*pot_Pr_pr_in;

		//Clculo del coeficiente de transferencia de calor por conveccin forzada interna
		h_pr_i = (Nu_pr_i*K_pr_in) / di;

		//Clculo del nmero de Nusselt
		Tm_pr_o = (T5 + T6asum) / 2;

		//Clculo de las propiedades trmodinmicas
		Tpro1 = pow(Tm_pr_o, num_1);
		Tpro2 = pow(Tm_pr_o, num_2);
		Tpro3 = pow(Tm_pr_o, num_3);
		Tpro4 = pow(Tm_pr_o, num_4);
		Tpro5 = pow(Tm_pr_o, num_5);

        rho_pr_o = 1.00000751E+03 + 4.12453182E-02*Tpro5 - 7.26158539E-03*Tpro4 + 3.89860058E-05*Tpro3 - 1.21356829E-07*Tpro2;
		Pr_pr_o = 1.32916100E+01 - 4.30437257E-01*Tpro5 + 7.47644446E-03*Tpro4 - 6.61443405E-05*Tpro3 + 2.29809176E-07*Tpro2;
		miu_pr_o = 1.74208697E-03 - 5.10568150E-05*Tpro5 + 8.47487316E-07*Tpro4 - 7.35177149E-09*Tpro3 + 2.52888709E-11*Tpro2;
		Cp_pr_o = 4.19918341E+00 - 1.25654652E-03*Tpro5 + 3.16877370E-05*Tpro4 - 3.68914621E-07*Tpro3 + 1.97518528E-09*Tpro2;
		K_pr_o = 5.47259845E-01 + 2.08355828E-03*Tpro5 - 5.71874184E-06*Tpro4 - 7.36319189E-08*Tpro3 + 4.03698327E-10*Tpro2;
		mdot5 = Vdot5*rho_pr_o;
		G_pr_o = mdot5 / Ao_cr;

		mdot5 = Vdot5*rho_pr_o;
		G_pr_o = mdot5 / Ao_cr;

		//Clculo del nmero de Reynolds
		Ts = Tsup2asum;
		Ts1 = pow(Ts, num_1);
		Ts2 = pow(Ts, num_2);
		Ts3 = pow(Ts, num_3);
		Ts4 = pow(Ts, num_4);
		Ts5 = pow(Ts, num_5);

		//Nmero de Reynolds por el casco del intercambiador
		Re_pr_o = (G_pr_o*d_o) / (miu_pr_o);
		Pr_pr_s = 3e-07*Ts2 - 9E-05*Ts3 + 0.0092*Ts4 - 0.4833*Ts5 + 13.788;
		Re_pr_o1 = pow(Re_pr_o, num_6);
		Re_pr_o2 = pow(Re_pr_o, num_7);
		Re_pr_o3 = pow(Re_pr_o, num_8);
		Re_pr_o4 = pow(Re_pr_o, num_9);
		Re_pr_o5 = pow(Re_pr_o, num_11);
		raz_Pr_pr_o = (Pr_pr_o / Pr_pr_s);
		pot_Pr_pr_o = pow(raz_Pr_pr_o, num_10);
		raz_Xl_Xt = (Xt / Xl);
		pot_Xl_Xt = pow(raz_Xl_Xt, num_12);
		pot_Pr_pr_o2 = pow(Pr_pr_o, num_13);
		pot_Pr_pr_o3 = pow(Pr_pr_o, num_6);

		//Arreglo de tubos alineados
		if (tiptubo == 1) {
			//Arreglo de tubos alineado
			if (Re_pr_o > 0 && Re_pr_o <= 100) {
				Nu_pr_o = 0.9*Re_pr_o1*pot_Pr_pr_o2*pot_Pr_pr_o;
			}
			if (Re_pr_o > 100 && Re_pr_o <= 1000) {
				Nu_pr_o = 0.52*Re_pr_o2*pot_Pr_pr_o2*pot_Pr_pr_o;
			}
			if (Re_pr_o > 1000 && Re_pr_o <= 2e5) { Nu_pr_o = 0.27*Re_pr_o3*pot_Pr_pr_o2*pot_Pr_pr_o; }
			if (Re_pr_o > 2e5 && Re_pr_o <= 2e6) {
				Nu_pr_o = 0.033*Re_pr_o4*pot_Pr_pr_o3*pot_Pr_pr_o;
			}
		}

		if (tiptubo == 2) {
			//Arreglo de tubos escalonado
			if (Re_pr_o > 0 && Re_pr_o <= 500) { Nu_pr_o = 1.04*Re_pr_o1*pot_Pr_pr_o2*pot_Pr_pr_o; }
			if (Re_pr_o > 500 && Re_pr_o <= 1000) { Nu_pr_o = 0.71*Re_pr_o2*pot_Pr_pr_o2*pot_Pr_pr_o; }
			if (Re_pr_o > 1000 && Re_pr_o <= 2e5) { Nu_pr_o = 0.35*pot_Xl_Xt*Re_pr_o5*pot_Pr_pr_o2*pot_Pr_pr_o; }
			if (Re_pr_o > 2e5 && Re_pr_o <= 2e6) { Nu_pr_o = 0.031*pot_Xl_Xt*Re_pr_o4*pot_Pr_pr_o2*pot_Pr_pr_o; }
		}
		//Coeficiente de transferencia de calor por el casco es
		h_pr_o = (Nu_pr_o*K_pr_o) / d_o;

		// !Factores J para el clculo del coeficiente de transferencia de calor por el lado del casco
		Jc = 0.55 + 0.72*Fc; //Factor de correccin para la configuracin de los bafles
		r_s = (Ao_sb) / (Ao_sb + Ao_tb);
		rlm = (Ao_sb + Ao_tb) / Ao_cr;
		Jl = 0.44*(1 - r_s) + ((1 - 0.44*(1 - r_s))*exp(-2.2*rlm)); //correction factor for baffle leakage effects, including both tube - to - baffle and baffleto
		Nss_plus = Nss / Nr_cc;
		rb = Ao_bp / Ao_cr;
		Li_plus = Lb_i / Lb_c_;
		Lo_plus = Lb_o / Lb_c_;
		n = 0.6;
		Nr_c = Nr_cc + Nr_cw;
		if (Re_pr_o > 100) { C_1 = 1.25; }
		else { C_1 = 1.35; }


		pro_Nssplus = (1 - (2 * Nss_plus));
		pot_Nssplus = pow(pro_Nssplus, num_14);
		if (Nss_plus > 0.5) {
			Jb = 1;
		}
		else {
			Jb = exp(-C_1*rb*pot_Nssplus);
		}

		pot_Li_plus = pow(Li_plus, num_15);
		pot_Lo_plus = pow(Lo_plus, num_15);
		Js = (Nb - 1 + pot_Li_plus + pot_Lo_plus) / (Nb - 1 + Li_plus + Lo_plus);
		raz_Nr_c = (10 / Nr_c);
		num_16 = 0.18;
		pot_Jr = pow(raz_Nr_c, num_16);
		if (Re_pr_o > 20) {
			Jr = 1;
		}
		else {
			Jr = pot_Jr;
		}
		h_pr_o_real = Jc*Jl*Js*Jr*Jb*h_pr_o; //Clculo del coeficiente de transferencia de calor"

		//Clculo del coeficiente global de transferencia de calor
		Uo_inv = (1 / h_pr_o_real) + Ro_f + ((d_o*log(d_o / di)) / (2 * Kw)) + (Ri_f*d_o / di) + (1 / h_pr_i*d_o / di);
		Uo = 1 / Uo_inv; //Coeficiente Global de Transferencia de calor
		C_pr_i = mdot2*Cp_pr_in * 1000;
		C_pr_o = mdot5*Cp_pr_o * 1000;
		if (mdot2 > mdot5) {
			C_min = C_pr_o;
			C_max = C_pr_i;}
		else{
			C_min = C_pr_i;
			C_max = C_pr_o;
		}
		
		//Clculo de la efecividad

		q_max = C_min*(T5 - T2);
		Q_23 = mdot2*Cp_pr_in * 1000 * (T3asum - T2);
		eff = Q_23 / q_max;
		c_asterisco = C_min / C_max;
		//Clculo de la temperatura de salida de la carcasa
		T6 = T5 - eff*c_asterisco*(T5 - T2);
		
		//Clculo de la NTU
		double F = (((eff*c_asterisco) - 1) / (eff - 1));
		F_pot = pow(F, (1/Np));
		eff_1 = (F_pot - 1) / (F_pot - c_asterisco);
		potsumC_as = pow(1 + (c_asterisco*c_asterisco), 0.5);
		E = ((2 / eff) - (1 + (c_asterisco))) / potsumC_as;
		potNTU_l = pow((1 + (c_asterisco*c_asterisco)), -0.5);
		NTU = -potNTU_l*log((E - 1) / (E + 1));

		//Clculo de la longitud del precalentador
		L_calc = C_min*NTU / (Uo*N_t*d_o*M_PI);
		error = error + fabs(Lasum - L_calc);
		Lasum = L_calc;
		if (error <= 0.000001) {
			contador = 100001;
		}
		else { contador++; }
		iteracion++;
	}
	A_prec = M_PI*(d_o + di)*Lasum*N_t;
     /////////////////////////////////////////////////////////////////////////////////////
	 //MDULO DE CAIDA DE PRESIN DEL INTERCAMBIADOR
	 //CAIDA DE PRESIN EN LOS TUBOS 
	double nume, pot_sigma_c_i, f_id_pr_i, sigma_pr_i, pot_sigma_pr_i, num_19, num_18, k_c, k_e, deltaP_pr_i;
	nume = 2;
	num_19 = 0.5;
	pot_sigma_c_i = pow(nume, num_19);
	num_18 = -0.2;
	pot_Re_pr_i = pow(Re_pr_i, num_18);
	f_id_pr_i = 0.046*pot_Re_pr_i;
	sigma_pr_i = 2 * (pt - d_o) / (pot_sigma_c_i*pt);
	k_c = 0.3;  //Prdida por contraccin"
	k_e = 0.4; //Prdida por expansion"
	deltaP_pr_i = (mdot2*mdot2) / (2 * rho_pr_in*Ao_t*Ao_t)*(((4 * f_id_pr_i*Lasum) / di) + (1 - (sigma_pr_i*sigma_pr_i) + k_c) - (1 - (sigma_pr_i*sigma_pr_i) - k_e))*Np;

	//CAIDA DE PRESIN EN LA CORAZA 
	double pot_Re_pr_o, pot_Re_pr_o_1, f_id_pr_o, pot_f_id_o, miu_c_s, raz_miu_c_o, pot_miu_c_o, delta_Pbid, pot_Nss_plus, p, pot_r_lm, delta_P_cr, delta_P_w, pot_areas, G_w, nn, pot_Lb_o, pot_Lb_i, Delta_P_io;
	double Delta_P_pr_o;
	double b;
	D = 3.7;
	pot_Re_pr_o = pow(Re_pr_o, -0.476);
	pot_Re_pr_o_1 = pow(Re_pr_o, 0.52);
	b = 6.59 / (1 + (0.14*pot_Re_pr_o_1));
	f_id_pr_o = (1.33*(d_o / pt));
	pot_f_id_o = 3.5*pow(f_id_pr_o, b)*pot_Re_pr_o;
	miu_c_s = miu_pr_o;
	raz_miu_c_o = (miu_pr_o / miu_c_s);
	pot_miu_c_o = pow(raz_miu_c_o, 0.25);
	delta_Pbid = (4 * pot_f_id_o*G_pr_o*G_pr_o*Nr_cc / (2 * rho_pr_o))*pot_miu_c_o;
	pot_Nss_plus = pow((2 * Nss_plus), (0.33333));
	sita_b = exp(-D*rb*(1 - pot_Nss_plus));
	p = (-0.15*(1 + r_s) + 0.8);
	pot_r_lm = pow(rlm, p);
	sita_l = exp(-1.33*(1 + r_s)*pot_r_lm);
	delta_P_cr = delta_Pbid*(Nb - 1)*sita_b*sita_l;
	pot_areas = pow((Ao_cr*Ao_w), 0.5);
	G_w = mdot5 / pot_areas;
	delta_P_w = Nb*(2 + 0.6*Nr_cw)*((G_w*G_w) / (2 * rho_pr_o))*sita_l;
	n = 0.2;
	nn = 2 - n;
	pot_Lb_o = pow((Lb_c_ / Lb_o), nn);
	pot_Lb_i = pow((Lb_c_ / Lb_i), nn);
	sita_s = pot_Lb_o + pot_Lb_i;
	Delta_P_io = 2 * delta_Pbid*(1 + (Nr_cw / Nr_cc))*sita_b*sita_s;
	Delta_P_pr_o = delta_P_cr + Delta_P_io + delta_P_w;

	 //MODULO DE OPERACION DEL INTERCAMBIADOR
	double a, b_b, c, d, eff_1t,f, eff_tran,g,h;
	double T6_tran, T3_tran;
	double Q_tran;
	d = pow((1 + (c_asterisco*c_asterisco)), 0.5);
	a = 1 + c_asterisco + d;
	b_b = 1 + exp(-NTU*d);
	c = 1 - exp(-NTU*d);
	eff_1t = 2 * pow((a*(b_b / c)), -1);
	g = ((1 - (eff_1t*c_asterisco))/(1 - eff_1t));
	f = pow(g, Np);
	h=1;
	eff_tran = (f-h)/(f-c_asterisco);
	double time3;
    Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
	T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
	//T3_tran = T2_trans + eff_tran*(T5_trans - T2_trans);
	double Tg = Q_tran/(rho_pr_in*Vdot2*Cp_pr_in*1000);
	double V =(M_PI*(di*di)*Lasum*N_t)/4;
	double tera = V/Vdot2;
	//double T_o = T2_trans + 0.5;
	double time2 = time/0.000277778;
	time3 = time2-3600;
	double T_t = T2_trans;
	double T_o = T2_trans + 0.5;
	T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time2 / tera));
	
	time3 = time2 - 3600;
	if(time2>3600)
	{
		T_o = T3_tran;
		T2_trans = 25.3;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
       T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time3 / tera));
	
	}
	double time4 = time2-7200;
	if (time2>7200)
	{
		T_o = T3_tran;
		T2_trans = 26.7;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time4 / tera));
}
	double time5 = time2 - 10800;
	if (time2>10800)
	{
		T_o = T3_tran;
		T2_trans = 28.5;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time5 / tera));
	}

	double time6 = time2-14400;
	if (time2>14400)
	{
		T_o = T3_tran;
		T2_trans = 28.8;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time6/tera));
	}

	double time7 = time2-18000;
	if (time2>18000)
	{
		T_o = T3_tran;
		T2_trans = 28.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time7 / tera));
	}

	double time8 = time2-21600;
	if (time2>21600)
	{
		T_o = T3_tran;
		T2_trans = 28.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time8 / tera));
	}
	double time9 = time2-25200;
	if (time2>25200)
	{
		T_o = T3_tran;
		T2_trans = 28.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time9 / tera));
	}

	double time10 = time2-28800;
	if (time2>28800)
	{
		T_o = T3_tran;
		T2_trans = 27.4;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time10 / tera));
	}

	double time11 = time2 - 32400;
	if (time2>32400)
	{
		T_o = T3_tran;
		T2_trans = 25.2;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time11 / tera));
	}

	double time12 = time2 - 36000;
	if (time2>36000)
	{
		T_o = T3_tran;
		T2_trans = 26;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time12/tera));
	}

	double time13 = time2 - 39600;
	if (time2>39600)
	{
		T_o = T3_tran;
		T2_trans = 26.8;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time13/tera));
	}

	double time14 = time2 - 43200;
	if (time2>43200)
	{
		T_o = T3_tran;
		T2_trans = 25.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time14/ tera));
	}

	double time15= time2-46800;
	if (time2>46800)
	{
		T_o = T3_tran;
		T2_trans = 26.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time15/tera));
	}
	
	double time16 = time2-50400;
	if (time2>50400)
	{
		T_o = T3_tran;
		T2_trans = 25.8;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time16/tera));
	}
	double time17 = time2 - 54000;
	if (time2>54000)
	{
		T_o = T3_tran;
		T2_trans = 25;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time17/tera));
	}

	double time18 = time2-57600;
	if (time2>57600)
	{
		T_o = T3_tran;
		T2_trans = 25.2;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time18/tera));
	}

	double time19=time2-61200;
	if (time2>61200)
	{
		T_o = T3_tran;
		T2_trans = 22.8;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time19/tera));
	}

	double time20 = time2 - 64800;
	if (time2>64800)
	{
		T_o = T3_tran;
		T2_trans = 25.1;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time20/tera));
	}

	double time21 = time2 - 68400;
	if (time2>68400)
	{
		T_o = T3_tran;
		T2_trans = 26;
		Q_tran = eff_tran*C_min*(T5_trans - T2_trans);
		T6_tran = T5_trans - eff_tran*c_asterisco*(T5_trans - T2_trans);
		Tg = Q_tran / (rho_pr_in*Vdot2*Cp_pr_in * 1000);
		V = (M_PI*(di*di)*Lasum*N_t) / 4;
		tera = V / Vdot2;
		T3_tran = (Tg + T2_trans) - (Tg + T2_trans - T_o)*exp(-(time21/tera));
	}


	//double ht = 3600;
	//for (time2 = 0; time2 <=ht; time2+=1)
	//{
		//T3_tran = (1 * ((mdot2*Cp_pr_in * 1000 * (T2_trans - T_t)) + Q_tran)) / (rho_pr_in*V*Cp_pr_in * 1000) + T_t;
		//T_t = T3_tran;
		//time2+1;}

	//-----------------------------------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------
	//    SET THE STORAGE ARRAY AT THE END OF THIS ITERATION IF NECESSARY
	//      nitmes=
	//      stored(1)=
	//	    setStorageVars(STORED,NITEMS,INFO)
	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------
	//    REPORT ANY PROBLEMS THAT HAVE BEEN FOUND USING CALLS LIKE THIS:
	//      MESSAGES(-1,'put your message here','MESSAGE',IUNIT,ITYPE)
	//      MESSAGES(-1,'put your message here','WARNING',IUNIT,ITYPE)
	//      MESSAGES(-1,'put your message here','SEVERE',IUNIT,ITYPE)
	//      MESSAGES(-1,'put your message here','FATAL',IUNIT,ITYPE)
	//-----------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------
	//    SET THE OUTPUTS FROM THIS MODEL IN SEQUENTIAL ORDER AND GET OUT

	//		 Ao_cr
	xout[0] = N_t;//Ao_cr ;
	//		 Ao_bp
	xout[1] = Ao_bp;
	//		 Ao_sb
	xout[2] = Ao_sb;
	//		 Ao_w
	xout[3] =Ao_w;
	//		 Ao_tb
	xout[4] = A_prec;
	//		 h_pr_o_real
	xout[5] =h_pr_o_real;
	//		 Ao_t
	xout[6] =Ao_t;
	//		 h_pr_i
	xout[7] =h_pr_i;
	//		 Uo
	xout[8] =Uo;
	//		 T6
	xout[9] =T6;
	//		 Q23
	xout[10] = Q_23;
	//		 deltaP_pr_o
	xout[11] = Delta_P_pr_o;
	//		 Lasum
	xout[12] = Lasum;
	//		 Qperdidas
	xout[13] = Re_pr_o;
    // Vdot3
		xout[14] =Vdot2;
	// eff
		xout[15] = eff_tran;
	// eff
	xout[16] =NTU;
	// T3
	xout[17] =T3 ;
	//T3_tran
	xout[18]=T3_tran;
	// Q_pre_tran
	xout[19] = Q_tran;
	// T6_trans
	xout[20] = T6_tran;
	//		 deltaP_pr_i
	xout[21] = deltaP_pr_i;
	//-----------------------------------------------------------------------------------------------------------------------
	//    EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON
	return 1;
}
//-----------------------------------------------------------------------------------------------------------------------
